package cn.shop.front.controller;

import cn.shop.base.MyPage;
import cn.shop.front.entity.order.SimpleOrder;
import cn.shop.front.entity.req.GameOrderQueryReq;
import cn.shop.front.service.GameBindService;
import cn.shop.front.service.OrderService;
import cn.shop.utils.ApiResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 游戏内网页接口
 *
 * @author : 李一涵
 * @date : Created in 2022/5/22 15:52
 * @description :
 */
@RestController
@RequestMapping("/api/v1/game")
public class GameController {

    @Resource
    private OrderService orderService;
    @Resource
    private GameBindService gameBindService;

    /**
     * 查看商户下游戏
     *
     * @param uid 商户id
     * @return 返回结果
     */
    @GetMapping("/{uid}/all")
    public ApiResult<List<Map<String, Object>>> allGame(@PathVariable long uid) {
        return ApiResult.success(gameBindService.allGame(uid));
    }

    /**
     * 通过游戏id查看游戏分区
     *
     * @param gid 游戏id
     * @return 返回结果
     */
    @GetMapping("/{gid}/partitions")
    public ApiResult<List<Map<String, Object>>> partitionByGameId(@PathVariable long gid) {
        return ApiResult.success(gameBindService.allPartitionByGame(gid));
    }

    /**
     * 通过分区id获取游戏id
     * @param pid 分区id
     * @return 返回结果
     */
    @GetMapping("/gameid/{pid}")
    public ApiResult<Map<String, Object>> getGameId(@PathVariable long pid) {
        return ApiResult.success(gameBindService.getGame(pid));
    }

    /**
     * 查询订单
     *
     * @param page 分页信息
     * @param req 查询条件
     * @return 返回结果
     */
    @GetMapping("/orders")
    public ApiResult<MyPage<SimpleOrder>> list(MyPage<SimpleOrder> page, GameOrderQueryReq req) {
        return ApiResult.success(orderService.orderList(page, req));
    }

}
